package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.pojo.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.user.ShoppingCartService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    public Result insertShoppingCart( @RequestBody ShoppingCartDTO shoppingCartDTO){
        return shoppingCartService.insertShoppingCart(shoppingCartDTO);
    }

    /**
     * 查看购物车
     * @return
     */
    @GetMapping("/list")
    public Result<List<ShoppingCart>> selectShoppingCart(){
    	return shoppingCartService.selectShoppingCart();
    }

    /**
     * 删除购物车的一个菜品
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/sub")
    public Result deleteShoppingCart( @RequestBody ShoppingCartDTO shoppingCartDTO){

    	return shoppingCartService.deleteShoppingCart(shoppingCartDTO);
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public Result cleanShoppingCart(){
    	return shoppingCartService.cleanShoppingCart();
    }
}
